<!--
 * @Description: 审批流程设置
 * @Author: wind-lc
 * @version: 1.0
 * @Date: 2021-09-06 10:07:54
 * @LastEditTime: 2021-09-08 18:44:52
 * @FilePath: \cscec-pms-admin\src\views\project\approvalProcessSetting\index.vue
-->
<template>
  <base-breadcrumb class="flexMemberInfo-container">
    <a-spin :spinning="loading">
      <a-card>
        <title-name :title="$route.meta.title" />
        <!-- 审批流程设置 -->
        <div class="approval-process-setting">
          <a-form-model
            :model="form"
            :label-col="labelCol"
            :wrapper-col="wrapperCol"
          >
            <p>1，施工进度总计划审批流程是否经过“公司工程管理部经理、公司生产副经理”审批：</p>
            <a-form-model-item label="非重点项目">
              <a-radio-group
                v-model="form.masterPlanNotImportantProject"
                :disabled="$disabledPermission('seex_pm_039_edi_02')"
                name="masterPlanNotImportantProject"
                @change="setting('masterPlanNotImportantProject')"
              >
                <a-radio :value="true">
                  是
                </a-radio>
                <a-radio :value="false">
                  否
                </a-radio>
              </a-radio-group>
            </a-form-model-item>
            <a-form-model-item label="重点项目">
              <a-radio-group
                v-model="form.masterPlanImportantProject"
                :disabled="$disabledPermission('seex_pm_039_edi_02')"
                name="masterPlanImportantProject"
                @change="setting('masterPlanImportantProject')"
              >
                <a-radio :value="true">
                  是
                </a-radio>
                <a-radio :value="false">
                  否
                </a-radio>
              </a-radio-group>
            </a-form-model-item>
            <p class="approval-process-setting-same-line">
              2，施工进度总计划调整中含二级节点的审批流程是否经过“公司工程管理部经理、公司生产副经理”审批：
              <a-form-model-item label="">
                <a-radio-group
                  v-model="form.masterPlanSecondAdjust"
                  name="masterPlanSecondAdjust"
                  :disabled="$disabledPermission('seex_pm_039_edi_02')"
                  @change="setting('masterPlanSecondAdjust')"
                >
                  <a-radio :value="true">
                    是
                  </a-radio>
                  <a-radio :value="false">
                    否
                  </a-radio>
                </a-radio-group>
              </a-form-model-item>
            </p>
            <p>3，项目动态信息审批流程是否经过“分公司生产副经理、公司工程管理部经理”审批：</p>
            <a-form-model-item label="非重点项目">
              <a-radio-group
                v-model="form.dynamicNotImportantProject"
                :disabled="$disabledPermission('seex_pm_039_edi_02')"
                name="dynamicNotImportantProject"
                @change="setting('dynamicNotImportantProject')"
              >
                <a-radio :value="true">
                  是
                </a-radio>
                <a-radio :value="false">
                  否
                </a-radio>
              </a-radio-group>
            </a-form-model-item>
            <a-form-model-item label="重点项目">
              <a-radio-group
                v-model="form.dynamicImportantProject"
                :disabled="$disabledPermission('seex_pm_039_edi_02')"
                name="dynamicImportantProject"
                @change="setting('dynamicImportantProject')"
              >
                <a-radio :value="true">
                  是
                </a-radio>
                <a-radio :value="false">
                  否
                </a-radio>
              </a-radio-group>
            </a-form-model-item>
          </a-form-model>
          <p class="approval-process-setting-warning">
            注：流程修改后，在修改后提交的数据使用新流程，已提交的数据审批流程不变。
          </p>
        </div>
        <!-- 审批流程设置 -->
        <!-- 修改记录 -->
        <div class="approval-process-setting-log">
          <p>修改记录：</p>
          <b-table
            ref="table"
            :columns="columns"
            :request="loadData"
            :page-keys=" ['pageNo', 'pageSize', 'totalSize']"
            :is-show-count-bar="false"
            bordered
          />
        </div>
        <!-- 修改记录 -->
      </a-card>
    </a-spin>
  </base-breadcrumb>
</template>
<script>
import approvalProcessSetting from '@/api/project/approvalProcessSetting'
export default {
  name: 'ApprovalProcessSetting',
  components: {},
  data() {
    return {
      // 页面加载
      loading: true,
      // 表单布局
      labelCol: { span: 6 },
      wrapperCol: { span: 18 },
      // 表单
      form: {},
      // 表头
      columns: [
        {
          title: '序号',
          width: 80,
          align: 'center',
          customRender: (text, record, index) => {
            return index + 1
          }
        },
        {
          title: '修改项',
          dataIndex: 'modifyItemName'
        },
        {
          title: '修改后',
          width: 100,
          align: 'center',
          dataIndex: 'modifyAfter',
          customRender: (text) => {
            return text ? '是' : '否'
          }
        },
        {
          title: '修改人',
          width: 200,
          dataIndex: 'modifyName'
        },
        {
          title: '修改时间',
          width: 200,
          align: 'center',
          dataIndex: 'modifiedTime'
        }
      ],
      // 表格数据加载
      loadData: async (q) => {
        if (this.form) {
          const res = await approvalProcessSetting.scheduleProcessSetting({
            ...q,
            settingId: this.form.id
          })
          if (res.code === 200) {
            return { code: 200, data: res.data, ...res }
          }
          return { code: 200, data: [] }
        } else {
          return { code: 200, data: [] }
        }
      }
    }
  },
  mounted() {
    this.getData()
  },
  methods: {
    /**
     * @description: 获取流程信息
     * @param {void}
     * @return {void}
     */
    async getData() {
      this.loading = true
      const { data } = await approvalProcessSetting.query({})
      this.form = data
      this.loading = false
      this.$refs.table.getData(null, true)
    },
    /**
     * @description: 设置
     * @param {string} key
     * @return {void}
     */
    setting(key) {
      let str = ''
      str += key[0].toUpperCase()
      for (let i = 1; i < key.length; i++) {
        if (key[i] === key[i].toUpperCase()) {
          str += '_'
        }
        str += key[i].toUpperCase()
      }
      const vm = this
      this.$confirm({
        title: '提交确认',
        content: '请确认是否要修改？',
        onOk() {
          approvalProcessSetting
            .setting({
              modifyAfter: vm.form[key],
              modifyItem: str,
              settingId: vm.form.id
            })
            .then(({ code, message }) => {
              if (code === 200) {
                vm.$message.success('操作成功')
                vm.getData()
              } else {
                vm.form[key] = !vm.form[key]
                vm.$message.warning(message)
              }
            })
            .catch((error) => {
              vm.form[key] = !vm.form[key]
            })
        },
        onCancel() {
          vm.form[key] = !vm.form[key]
        }
      })
    }
  }
}
</script>
<style lang="less" scoped>
.approval-process-setting {
  .ant-form-item {
    margin-bottom: 10px;
  }
}
.approval-process-setting-same-line {
  display: flex;
  flex-wrap: nowrap;
  .ant-form-item {
    flex: 1;
    margin-top: -9px;
  }
}
.approval-process-setting-log p {
  margin-bottom: 20px;
}
.approval-process-setting-warning {
  color: red;
}
</style>
